package com.walle.concurrenttest.waitnotify;

/**
 * @author zhangjiapeng
 * @Package com.walle.concurrenttest.waitnotify
 * @Description: ${todo}
 * @date 2019/2/27 14:23
 */
public class PrintABC {

    private char c;

    public PrintABC(char c) {
        this.c = c;
    }

    public synchronized void print(char exp){
        while (exp != c){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("线程" + Thread.currentThread().getName() + "打印->" + c);
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public synchronized void setNext(char c){
        this.c = c;
        this.notifyAll();
    }
}
